<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE ${"mapper"} PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<!-- ${((tableInfo.remark)?length>0)?string(tableInfo.remark,tableInfo.tableName)}  -->
<mapper namespace="${entityPackage}.${entityName}Mapper">

    <!--通用表字段列表-->
    <resultMap id="BaseResultMap"
               type="${entityPackage}.${entityName}">
    <#list tableInfo.columnInfos as columnInfo>
        <result column="${columnInfo.name}" property="${columnInfo.javaName}"
                jdbcType="${columnInfo.ormType}"/>
    </#list>
    </resultMap>
    <!--通用表字段列表-->

    <!--通用查询条件组装-->
    <sql id="whereCondition">
    <#list tableInfo.columnInfos as columnInfo>
        <if test="${columnInfo.javaName} != null">
            AND `${columnInfo.name}`=${"#"}{${columnInfo.javaName},jdbcType=${columnInfo.ormType}}
        </if>
    </#list>
    </sql>

    <!--like查询条件组装-->
    <sql id="whereLikeCondition">
    <#list tableInfo.columnInfos as columnInfo>
        <if test="${columnInfo.javaName} != null">
            AND `${columnInfo.name}` LIKE ${"#"}{${columnInfo.javaName},jdbcType=${columnInfo.ormType}}
        </if>
    </#list>
    </sql>

    <!--查询字段列表拼装-->
    <sql id="baseColumnList">
    <#list tableInfo.columnInfos as columnInfo>
    ${"    "}`${columnInfo.name}`<#if columnInfo_index!=(tableInfo.columnInfos?size-1)>,</#if>
    </#list>
    </sql>

    <!--
    方法名称: insert
    调用路径: ${entityName}Mapper.insert
    开发信息:
    处理信息: 保存记录
    -->
    <insert id="insert"
            parameterType="${entityPackage}.${entityName}">
        INSERT INTO ${tableInfo.tableName}
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <#list tableInfo.columnInfos as columnInfo>
            <if test="${columnInfo.javaName} != null">
            ${"    "}`${columnInfo.name}`,
            </if>
        </#list>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
        <#list tableInfo.columnInfos as columnInfo>
            <if test="${columnInfo.javaName} != null">
            ${"    "}${"#"}{${columnInfo.javaName},jdbcType=${columnInfo.ormType}},
            </if>
        </#list>
        </trim>
    </insert>

    <!--
    方法名称: update
    调用路径: ${entityName}Mapper.update
    开发信息:
    处理信息: 修改记录
    -->
    <update id="update"
            parameterType="${entityPackage}.${entityName}">
        UPDATE ${tableInfo.tableName}
        <set>
        <#list tableInfo.columnInfos as columnInfo>
            ${"    "}`${columnInfo.name}` = ${"#"}{${columnInfo.javaName},jdbcType=${columnInfo.ormType}},
        </#list>
        </set>
        WHERE 1=1
        <if test="${tableInfo.primaryKey.name} !=null">
            AND `${tableInfo.primaryKey.name}` = ${"#"}{${tableInfo.primaryKey.javaName},jdbcType=${tableInfo.primaryKey.ormType}}
        </if>
    </update>

    <!--
    方法名称: updateByPrimaryKey
    调用路径: ${entityName}Mapper.updateByPrimaryKey
    开发信息:
    处理信息: 修改记录
    -->
    <update id="updateByPrimaryKey"
            parameterType="${entityPackage}.${entityName}">
        UPDATE ${tableInfo.tableName}
        <set>
        <#list tableInfo.columnInfos as columnInfo>
            <if test="${columnInfo.javaName} != null">
                ${"    "}`${columnInfo.name}` = ${"#"}{${columnInfo.javaName},jdbcType=${columnInfo.ormType}},
            </if>
        </#list>
        </set>
        WHERE 1=1
        AND `${tableInfo.primaryKey.name}` = ${"#"}{${tableInfo.primaryKey.javaName},jdbcType=${tableInfo.primaryKey.ormType}}
    </update>

    <!--
    方法名称: delete
    调用路径:${entityName}Mapper.delete
    开发信息:
    处理信息: 删除记录
    -->
    <delete id="delete"
            parameterType="${entityPackage}.${entityName}">
        DELETE FROM ${tableInfo.tableName}
        WHERE 1=1
        <include refid="whereCondition"/>
    </delete>

    <!--
    方法名称: deleteByPrimaryKey
    调用路径:${entityName}Mapper.deleteByPrimaryKey
    开发信息:
    处理信息: 删除记录
    -->
    <delete id="deleteByPrimaryKey"
            parameterType="${entityPackage}.${entityName}">
        DELETE FROM ${tableInfo.tableName}
        WHERE 1=1
        WHERE 1=1
        AND `${tableInfo.primaryKey.name}` = ${"#"}{${tableInfo.primaryKey.javaName},jdbcType=${tableInfo.primaryKey.ormType}}
    </delete>

    <!--
    方法名称: findBy
    调用路径: ${entityName}Mapper.findBy
    开发信息:
    处理信息: 根据主键查询记录
    -->
    <select id="findBy"
            parameterType="${entityPackage}.${entityName}"
            resultType="${entityPackage}.${entityName}">
        SELECT
        <include refid="baseColumnList"/>
        FROM ${tableInfo.tableName}
        WHERE 1=1
        <include refid="whereCondition"/>
        <!--排序-->
        <include refid="CommonEntity.sort"/>
        <!--一条-->
        <include refid="CommonEntity.selectOne"/>
    </select>

    <!--
    方法名称: countBy
    调用路径: ${entityName}Mapper.countBy
    开发信息:
    处理信息: 根据主键统计记录
    -->
    <select id="countBy"
            parameterType="${entityPackage}.${entityName}"
            resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM ${tableInfo.tableName}
        WHERE 1=1
        <include refid="whereCondition"/>
    </select>

    <!--
    方法名称: getPaginationList
    调用路径: ${entityName}Mapper.getPaginationList
    开发信息:
    处理信息: 分页查询记录
    -->
    <select id="getPaginationList"
            parameterType="${entityPackage}.${entityName}"
            resultType="${entityPackage}.${entityName}">
        SELECT
        <include refid="baseColumnList"/>
        FROM ${tableInfo.tableName}
        WHERE 1=1
        <include refid="whereCondition"/>
        <!--排序-->
        <include refid="CommonEntity.sort"/>
        <!-- 分页条 -->
        <include refid="CommonEntity.pagination"/>
    </select>

    <!--
    方法名称: getPaginationList-count
    调用路径: ${entityName}Mapper.getPaginationList-count
    开发信息:
    处理信息: 查询记录数
    -->
    <select id="getPaginationList-count"
            parameterType="${entityPackage}.${entityName}"
            resultType="int">
        SELECT count(1) FROM ${tableInfo.tableName}
        WHERE 1=1
        <include refid="whereCondition"/>
    </select>

    <!--
    方法名称: getList
    调用路径: ${entityName}Mapper.getList
    开发信息:
    处理信息: 根据条件查询记录
    -->
    <select id="getList"
            parameterType="${entityPackage}.${entityName}"
            resultType="${entityPackage}.${entityName}">
        SELECT
        <include refid="baseColumnList"/>
        FROM ${tableInfo.tableName}
        WHERE 1=1
        <include refid="whereCondition"/>
        <!--排序-->
        <include refid="CommonEntity.sort"/>
        limit 0,100
    </select>

    <!--
    方法名称: likeBy
    调用路径: ${entityName}Mapper.likeBy
    开发信息:
    处理信息: 分页查询记录
    -->
    <select id="likeBy"
            parameterType="${entityPackage}.${entityName}"
            resultType="${entityPackage}.${entityName}">
        SELECT
        <include refid="baseColumnList"/>
        FROM ${tableInfo.tableName}
        WHERE 1=1
        <include refid="whereLikeCondition"/>
        <!--排序-->
        <include refid="CommonEntity.sort"/>
        <!-- 分页条 -->
        <include refid="CommonEntity.pagination"/>
    </select>

    <!--
    方法名称: likeBy-count
    调用路径: ${entityName}Mapper.likeBy-count
    开发信息:
    处理信息: 查询记录数
    -->
    <select id="likeBy-count"
            parameterType="${entityPackage}.${entityName}"
            resultType="int">
        SELECT count(1) FROM ${tableInfo.tableName}
        WHERE 1=1
        <include refid="whereLikeCondition"/>
    </select>

    <!--用户自定义代码开始-->
${userCustomCode}
    <!--用户自定义代码结束-->
</mapper>